package com.foreknow.service.impl;

import com.foreknow.dao.UserDao;
import com.foreknow.dao.UserMapper;
import com.foreknow.entity.User;
import com.foreknow.entity.UserExample;
import com.foreknow.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Autowired
    private UserMapper userMapper;

    @Override
    public User queryByPassword(User user) throws Exception {

        return userDao.queryByPassword(user);
    }

    @Override
    public User queryByUserid(Integer userId) throws Exception {
        return userMapper.selectByPrimaryKey(userId);
    }

    @Override
    public List<User> queryUserbyDeptAndRegistle(Integer deptId, Integer registleId, Integer pageSize, Integer currentPage) throws Exception {
        Integer start = (currentPage - 1) * pageSize;
        Integer offset = pageSize;


        return userDao.queryUserbyDeptAndRegistle(deptId, registleId, start, offset);
    }

    @Override
    public int countOfDeptAndRegistle(Integer deptId, Integer registleId) throws Exception {
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andDeptidEqualTo(deptId);
        criteria.andRegistleidEqualTo(registleId);

        return userMapper.countByExample(example);
    }
}
